<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: LXListMenuPortlet.php 289 2008-11-14 05:34:40Z steen.rabol@gmail.com $
 * @package Pradoportal.Porttlets.LXListMenuPortlet
 *
 */

Prado::using('Application.Common.XListMenu');
Prado::using('Application.Portlets.Portlet');
Prado::using('Application.Common.Data.PortalConfigRecord');
Prado::using('Application.Portlets.LXListMenuPortlet.Common.LXListmenuRecord');

class LXListMenuPortlet extends Portlet
{
	public function onLoad($param)
	{
		$mainmenu = null;
		parent::onLoad($param);
		// Get value from config
		$crow	= PortalConfigRecord::finder()->findByname('LXListMenu_' . $this->Parameters['id']);
		if($crow)
		{
			$css		=  explode(";",$crow->value);
			$acss		= (isset($css[0]) ? $css[0] : "");
			$icss		= (isset($css[1]) ? $css[1] : "");
			$menucss	= (isset($css[2]) ? $css[2] : "");
			$menutitle	= (isset($css[3]) ? $css[3] : "");
		}
		else
		{
			$acss 		= "";
			$icss		= "";
			$menucss	= "";
			$menutitle	= "";
		}

		$localItems	= LXListmenuRecord::finder()->findAllByid($this->Parameters['id']);
		if($localItems !== null)
		{
			if($menutitle != "")
			{
				$this->MenuTitle->Visible	= true;
				$this->MenuTitleText->Text	= $menutitle;
			}

			$mainmenu					= new XListMenu();
			$mainmenu->ActiveCssClass	= $acss;
			$mainmenu->InactiveCssClass	= $icss;
			$mainmenu->CssClass			= $menucss;

			foreach($localItems as $item)
			{
				$mi					= new XListMenuItem();
				$mi->PagePath		= $item->pagename;
				$mi->NavigateUrl	= $this->Service->constructUrl($item->pagename);
				$mi->Text			= $item->displayname;
				$mainmenu->addParsedObject($mi);
			}

			if($this->findControl("LXListMenuPlaceholder"))
			{
				$this->LXListMenuPlaceholder->addParsedObject($mainmenu);
			}
		}
	}
}
?>